package cn.mabach.order.service.impl;


import cn.mabach.DTO.PageUtils;
import cn.mabach.DTO.RS;
import cn.mabach.order.dao.PreferentialDao;
import cn.mabach.order.entity.PreferentialEntity;
import cn.mabach.order.service.PreferentialService;
import cn.mabach.utils.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class PreferentialServiceImpl extends ServiceImpl<PreferentialDao, PreferentialEntity> implements PreferentialService {

    @Override
    public RS<PageUtils> queryPage(@RequestParam Map<String, Object> params) {
        IPage<PreferentialEntity> page = this.page(
                new Query<PreferentialEntity>().getPage(params),
                new QueryWrapper<PreferentialEntity>()
        );
        if (page==null){
            return RS.error();
        }
        return RS.ok(new PageUtils(page));
    }





    @Override
    public RS<PreferentialEntity> getByIdE(@RequestParam("id") Integer id) {
            PreferentialEntity res = this.getById(id);
        if (res==null){
            return RS.error();
        }
        return RS.ok(res);
    }

    @Override
    public RS saveE(@RequestBody  PreferentialEntity entity) {
        boolean b = this.save(entity);
        if (!b){
            return RS.error();
        }
        return RS.ok();
    }

    @Override
    public RS updateByIdE(@RequestBody PreferentialEntity entity) {
        boolean b = this.updateById(entity);
        if (!b){
            return RS.error();
        }
        return RS.ok();
    }

    @Override
    public RS removeByIdsE(@RequestBody List<Integer> ids) {
        boolean b = this.removeByIds(ids);
        if (!b){
            return RS.error();
        }
        return RS.ok();
    }

}